package com.hejia.alauda.entity;

import static com.hejia.alauda.utils.RateUtil.calculateDate;
import static org.apache.commons.lang3.time.DateUtils.addDays;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;

public class Invitation extends BaseEntity {
	
	public static final int TYPE_INVITE = 1;
	public static final int TYPE_FINANCIAL = 2;
	public static final int TYPE_CREDIT = 3;
	public static final int TYPE_SPRING_2015 = 4;
	public static final int TYPE_TCL_RED_PACKETS = 5;
	public static final int TYPE_HUSHEN_300 = 6;
	public static final int TYPE_YOUKU_2015 = 8;
	public static final int TYPE_ANNUAL_MEETING_2015 = 99;
	
	public static final double DEFAULT_AMOUNT = 1000;
	public static final int DEFAULT_TERM = 7;
	/**
	 * 
	 */
	private static final long serialVersionUID = 6885696033855223741L;
	
	@Column
	private User invitee; //被邀请人 
	
	@Column
	private User inviter; //邀请人
	
	@Column
	private Double amount; //理财金数量
	
	@Column
	private Integer term; //理财期限
	
	@Column
	private Double income; //收益
	
	@Column
	private Integer type; //活动类型
	
	@Column
	private Status status; // 状态
	
	@Column
	private BigDecimal interestRate; //利率
	
	@Column
	private String ancestor; //祖先邀请用户层次
	
	private Long count; //资产包的数量

	public String getAncestor() {
		return ancestor;
	}

	public void setAncestor(String ancestor) {
		this.ancestor = ancestor;
	}

	public User getInvitee() {
		return invitee;
	}

	public void setInvitee(User invitee) {
		this.invitee = invitee;
	}

	public User getInviter() {
		return inviter;
	}

	public void setInviter(User inviter) {
		this.inviter = inviter;
	}

	public Long getCount() {
		return count;
	}

	public void setCount(Long count) {
		this.count = count;
	}
	
	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

	public Integer getTerm() {
		return term;
	}

	public void setTerm(Integer term) {
		this.term = term;
	}

	public Double getIncome() {
		return income;
	}

	public void setIncome(Double income) {
		this.income = income;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}
	
	public BigDecimal getInterestRate() {
		return interestRate;
	}

	public void setInterestRate(BigDecimal interestRate) {
		this.interestRate = interestRate;
	}

	public String getStatusStr() {
		String str = "未知状态";
		if(status!=null){
			switch (status) {
			case CASHED:
				str = "已到期";
				break;
			case CANRECEIVE:
				str = "已到期";
				break;
			case UNCASHED:
				int interval = calculateDate(new Date(), addDays(getCreateDate(),term-1));
				str = interval>=0 ? (interval>0 ? (interval + "天后到期") : "今日到期") : "已到期";
				break;
			default:
				break;
			}
		}
		return str;
	}
	
	public static enum Status {
		CANRECEIVE,//可领取
		UNCASHED,//未兑付
		CASHED,
		TRADE; //已兑付
	}
}
